package com.binhthuan.catechist.client.viewer;

import java.util.Date;

import com.binhthuan.catechist.client.ECApplication;
import com.binhthuan.catechist.client.data.TrainerDS;
import com.binhthuan.catechist.shared.constant.Parameter;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.widgets.viewer.DetailFormatter;
import com.smartgwt.client.widgets.viewer.DetailViewerField;

public class TrainerViewer extends PersonViewer {

    public TrainerViewer(TrainerDS dataSource) {
        super(dataSource);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.binhthuan.catechist.client.viewer.PersonViewer#getAdvanceFields()
     */
    @Override
    public DetailViewerField[] getAdvanceFields() {
        DetailViewerField feastDay = new DetailViewerField(Parameter.FEAST_DAY);
        feastDay.setTitle(ECApplication.getConstants().feastDay());
        feastDay.setDetailFormatter(new DetailFormatter() {

            @Override
            public String format(Object value, Record record, DetailViewerField field) {
                if (value instanceof Date) {
                    return DateTimeFormat.getFormat("dd/MM").format((Date) value);
                }
                return value.toString();
            }
        });

        DetailViewerField email = new DetailViewerField(Parameter.EMAIL);
        email.setTitle(ECApplication.getConstants().email());

        DetailViewerField address = new DetailViewerField(Parameter.ADDRESS);
        address.setTitle(ECApplication.getConstants().address());

        DetailViewerField status = new DetailViewerField(Parameter.STATUS_NAME);
        status.setTitle(ECApplication.getConstants().status());

        return new DetailViewerField[] { feastDay, email, address, status };
    }
}
